package com.kzd.gtgame.jetpack.manager

import com.kzd.gtgame.app.*
import com.kzd.gtgame.base.BaseManager
import com.kzd.gtgame.entity.*
import com.module.lemlin.http.HttpResponseDataE
import com.module.lemlin.http.HttpResponseDataT
import rxhttp.RxHttp
import rxhttp.await

class GameRepository : BaseManager() {

    /**
     * 游戏详情
     *
     * @param gid 游戏id
     * */
    suspend fun gameDetails(gid: String): HttpResponseDataT<GameDetails> =
        RxHttp.postForm(APP_GAME_INFO)
            .add("id", gid)
            .await()

    /**
     * 游戏详情-底部猜一猜
     *
     * @param page 分页
     * @param gid 游戏id
     * */
    suspend fun gameGuess(
        page: String, gid: String
    ): HttpResponseDataE<GameBean> = RxHttp.postForm(NEW_APPS_GET_DETAIL_LIST)
        .add("p", page)
        .add("id", gid)
        .await()


    /**
     * 游戏评论
     *
     * @param gid 游戏id
     * @param page 分页
     * @param limit 条数
     * */
    suspend fun gameDiscuss(
        gid: String, page: String, limit: String
    ): HttpResponseDataE<GameDiscuss> = RxHttp.postForm(NEW_APPS_GET_PINGLUN)
        .add("id", gid)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 游戏评论回复
     *
     * @param gid 游戏id
     * @param page 分页
     * @param limit 条数
     * */
    suspend fun gameDiscussReply(
        id: String, page: String, limit: String
    ): HttpResponseDataE<GameDiscuss> = RxHttp.postForm(NEW_APPS_SON_PINGLUN_LIST)
        .add("id", id)
        .add("p", page)
        .add("limit", limit)
        .await()


    /**
     * 游戏评论点赞
     *
     * @param id 评论id
     * */
    suspend fun gameDiscussGreat(id: String): DiscussGreatResponse =
        RxHttp.postForm(PERSONAL_PINGLUN_ZAN)
            .add("id", id)
            .await()

    /**
     * 游戏详情-福利
     *
     * @param gameId 游戏id
     * */
    suspend fun gameWelfare(gameId: String): HttpResponseDataT<GameWelfare> =
        RxHttp.postForm(NEW_APPS_FULI)
            .add("game_id", gameId)
            .await()

    /**
     * 游戏详情-开服
     * */
    suspend fun gameService(
        gameId: String, page: String, limit: String
    ): HttpResponseDataE<GameService1> = RxHttp.postForm(NEW_APPS_GAME_SERVER)
        .add("id", gameId)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 游戏详情-开服提醒
     * */
    suspend fun gameServiceRemind(id: String): ServiceRemindResponse =
        RxHttp.postForm(NEW_APPS_REMIND_SERVER)
            .add("id", id)
            .await()


    /**
     * 游戏详情-交易
     * */
    suspend fun gameBargain(
        keyword: String, gameId: String, sort: String, system: String, page: String, limit: String
    ): HttpResponseDataE<GameBargain> = RxHttp.postForm(PERSONAL_TRADE)
        .add("keyword", keyword)
        .add("game_id", gameId)
        .add("sort", sort)
        .add("system", system)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 游戏分类tab
     * */
    suspend fun gameClassify(): HttpResponseDataE<ClassifyTab> =
        RxHttp.postForm(APP_FENLEI)
            .await()

    /**
     * 游戏分类列表
     *
     * @param type 分类id
     * @param page 分页
     * */
    suspend fun gameList(
        type: String, page: String
    ): HttpResponseDataE<GameBean> = RxHttp.postForm(APP_FENLEI_GAME)
        .add("type", type)
        .add("p", page)
        .await()

    /**
     * 游戏分类-精选
     *
     * @param systemType 1手游2h5
     * @param ios 1=ios2=安卓
     * */
    suspend fun gameFeatured(
        systemType: String, ios: String
    ): HttpResponseDataT<GameFeatured> = RxHttp.postForm(NEW_APPS_GET_SELECTED_LIST)
        .add("system_type", systemType)
        .add("ios", ios)
        .await()

    /**
     * 游戏排行
     *
     * @param type 0热门榜1新游榜
     * @param cid 分类id
     * @param page 分页
     * */
    suspend fun gameRanking(
        type: String, cid: String, page: String
    ): HttpResponseDataE<GameBean> = RxHttp.postForm(APP_PAIHANG)
        .add("t", type)
        .add("type", cid)
        .add("p", page)
        .await()
}